package com.selfdriving.activity;

import net.tsz.afinal.annotation.view.ViewInject;

import com.selfdriving.R;

import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.Html;
import android.text.Spanned;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class RegisterTwoActivity extends BaseActivity {

	@ViewInject(id = R.id.top_text_name)
	TextView top_text_name;

	@ViewInject(id = R.id.top_text_step)
	TextView top_text_step;

	@ViewInject(id = R.id.tvVerify)
	TextView tvVerify;

	@ViewInject(id = R.id.btn_send, click = "btn_send")
	Button btn_send;

	@ViewInject(id = R.id.btn_back, click = "btn_back")
	Button btn_back;

	@ViewInject(id = R.id.btn_ok, click = "btn_ok")
	Button btn_ok;

	private TimeCount time;

	private String strForm = "验证码已经发送到 <font color='#f4a600'><U >%s</U></font>";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.register_two);
		time = new TimeCount(60000, 1000);
		top_text_name.setText("输入手机验证码");
		top_text_step.setText("2/5");
	}

	public void btn_send(View v) {
		String txtstr = String.format(strForm, "(+86)15279107963");
		Spanned spt = Html.fromHtml(txtstr);
		tvVerify.setText(spt);
		tvVerify.setVisibility(View.VISIBLE);
		time.start();
	}

	public void btn_back(View v) {
		this.finish();
	}
	
	public void btn_ok(View v){
		Intent intent = new Intent(this,RegisterThreeActivity.class);
		startActivity(intent);
	}

	class TimeCount extends CountDownTimer {
		public TimeCount(long millisInFuture, long countDownInterval) {
			super(millisInFuture, countDownInterval);// 参数依次为总时长,和计时的时间间隔
		}

		@Override
		public void onFinish() {// 计时完毕时触发
			btn_send.setText("重发");
			btn_send.setClickable(true);
		}

		@Override
		public void onTick(long millisUntilFinished) {// 计时过程显示
			btn_send.setClickable(false);
			btn_send.setText(millisUntilFinished / 1000 + "秒");
		}
	}
}
